package com.bwie.controller;

import cn.hutool.core.io.file.FileNameUtil;
import com.bwie.pojo.R;
import com.bwie.pojo.Spe;
import com.bwie.pojo.utile.Pageinfo;
import com.bwie.service.SpeService;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author DarkClown
 * @date 2024-07-22 15:49
 * @project_name hight5
 * @parem
 **/
@RestController
@RequestMapping("/spe/spe")
public class SpeController {
    @Autowired
    SpeService speService;

    @Autowired
    FastFileStorageClient fastFileStorageClient;

    //查询列表
    @RequestMapping("/spelist")
    private R speList(String keyword){

        return speService.selectList(keyword);
    }

    //修改
    @RequestMapping("/updateById")
    private R dleIds(@RequestBody Spe spe){
        return speService.updateBySpe(spe);
    }

    //添加
    @RequestMapping("/addSpe")
    private R addSpe(@RequestBody Spe spe){
        return speService.addSpe(spe);
    }

    //删除
    @RequestMapping("/delectByIds")
    private R delectByIds(Integer[] ids){
        return speService.delectByIds(ids);
    }


    @RequestMapping("/delectByIdToOption/{id}")
    private R delectByIdToOption(@PathVariable(value = "id") Integer id){
        return speService.delectByIdToOption(id);
    }


//    @RequestMapping("/uploadFile")
//    private R uploadFile(MultipartFile file) throws IOException {
//        String filename = file.getOriginalFilename();
//
//        String[] split = filename.split("\\.");
//        String s = FileNameUtil.extName(file.getOriginalFilename());
//
//        String fullPath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), split[1], null).getFullPath();
//
//        return R.ok( "http://192.168.81.128:8888/"+fullPath);
//
//    }
}
